package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

public class Power extends AbstractMapleStoryObject{
    public static Image[] imgs = new Image[10];
    static {
        for (int i = 0; i < 10; i++) {
            imgs[i] = ImageUtil.getImage("power" + i);
        }
    }
    public Power(){
        this.speed = 5;
        this.live = true;
    }

    /**
     * 每一个伤害值
     */
    public int value;

    public Power(MapleStoryClient msc,int x, int y){
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.value = msc.hero.hitValue;
    }
    @Override
    public void draw(Graphics g) {
        if (!live) {
            msc.powers.remove(this);
            return;
        }
        /*Font f = g.getFont();
        g.setFont(new Font("微软雅黑",Font.BOLD,60));
        g.drawString(value + "",x,y);
        g.setFont(f);*/
        drawValue(g);
        move();
    }

    /**
     * 使用图片画伤害值
     * @param g 画笔
     */
    public void drawValue(Graphics g){
        int power = this.value; // 2587
        if (power >= 9999) {
            power = 9999;
        }
        int units = power % 10; // 7
        power = power / 10; // 258
        int tens = power % 10; // 8;
        power = power / 10; // 25
        int hundreds = power % 10; // 5;
        power = power / 10; // 2
        int thousands = power;
        if (units != 0 && tens == 0 && hundreds == 0 && thousands == 0){
            // 只画个位
            g.drawImage(imgs[units],x,y,null);
        }
        if (tens != 0 && hundreds == 0 && thousands == 0){
            // 画十位
            g.drawImage(imgs[tens],x,y,null);
            // 画个位
            g.drawImage(imgs[units],x + 25,y - 3,null);
        }
        if (hundreds != 0 && thousands == 0){
            // 画百位
            g.drawImage(imgs[hundreds],x,y,null);
            // 画十位
            g.drawImage(imgs[tens],x + 25,y - 3,null);
            // 画个位
            g.drawImage(imgs[units],x + 50,y,null);
        }
        if (thousands != 0){
            // 画千位
            g.drawImage(imgs[thousands],x,y,null);
            // 画百位
            g.drawImage(imgs[hundreds],x + 25,y - 3,null);
            // 画十位
            g.drawImage(imgs[tens],x + 50,y,null);
            // 画个位
            g.drawImage(imgs[units],x + 75,y - 3,null);
        }
    }

    @Override
    public void move() {

        if (this.y <= 175){
            if (this.y <= 0){
                this.live = false;
            }
            this.y -= speed;
        }else if (this.y <= 365){
            if (this.y <= 180){
                this.live = false;
            }
            this.y -= speed;
        }else if (this.y <= 725){
            if (this.y <= 500) {
                this.live = false;
            }
            this.y -= speed;
        }
    }
}
